package com.jxinternet.platform.services.repository.convert;


import java.util.List;
import java.util.stream.Collectors;
import org.springframework.util.CollectionUtils;

/**
 * dto -> model and model -> dto 工具类
 * @author : cabbage
 */
public interface BaseConvert<Model, MysqlDomain, CassandraDomain> {

    /**
     * 将model 转换成mysql实体类
     * @param model
     * @return
     */
    MysqlDomain convertMysql(Model model);

    /**
     * 将model集合转成mysql集合
     * @param models
     * @return
     */
    default List<MysqlDomain> convertMysql(List<Model> models) {
        if (!CollectionUtils.isEmpty(models)) {
            return models.stream().map(model -> this.convertMysql(model)).collect(Collectors.toList());
        }
        return null;
    }

    /**
     * 将model 转换成cassandra实体类
     * @param model
     * @return
     */
    CassandraDomain convertCassandra(Model model);

    /**
     * 将model集合转成cassandra集合
     * @param models
     * @return
     */
    default List<CassandraDomain> convertCassandra(List<Model> models) {
        if (!CollectionUtils.isEmpty(models)) {
            return models.stream().map(model -> this.convertCassandra(model)).collect(Collectors.toList());
        }
        return null;
    }

    /**
     * 将mysqlDomain转成model类
     * @param mysqlDomain
     * @return
     */
    Model convertMysqlDomainToModel(MysqlDomain mysqlDomain);

    /**
     * 将mysqlDomains集合转成model
     * @param mysqlDomains
     * @return
     */
    default List<Model> convertMysqlDomainToModel(List<MysqlDomain> mysqlDomains) {
        if (!CollectionUtils.isEmpty(mysqlDomains)) {
            return mysqlDomains.stream().map(mysqlDomain -> this.convertMysqlDomainToModel(mysqlDomain)).collect(Collectors.toList());
        }
        return null;
    }

    /**
     * 将cassandraDomain转成model类
     * @param cassandraDomain
     * @return
     */
    Model convertCassandraDomainToModel(CassandraDomain cassandraDomain);

    /**
     * 将mysqlDomains集合转成model
     * @param cassandraDomains
     * @return
     */
    default List<Model> convertCassandraDomainToModel(List<CassandraDomain> cassandraDomains) {
        if (!CollectionUtils.isEmpty(cassandraDomains)) {
            return cassandraDomains.stream().map(cassandraDomain -> this.convertCassandraDomainToModel(cassandraDomain)).collect(Collectors.toList());
        }
        return null;
    }


}
